// pages/search/search.js
import {
    goodsList
  } from "../../utils/http";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        goodsLists:[],
        history:{},
        index:0
    },
    aaa(e){
        let {goodsLists}=this.data
        console.log(e.currentTarget.dataset);
        this.setData({
            index:e.currentTarget.dataset.index
        })
        if(e.currentTarget.dataset.index==0){
            goodsList({nameLike: e.detail.value}).then(ress => {
                console.log('123', ress);
                if(ress.data){
                    goodsLists=ress.data.result
                }else{
                    console.log('暂无数据');
                }
                console.log(goodsLists);
                this.setData({
                  goodsLists
                })
              })
        }else if(e.currentTarget.dataset.index==1){
            goodsList({nameLike: e.detail.value,orderBy:'addedUp'}).then(ress => {
                console.log('123', ress);
                if(ress.data){
                    goodsLists=ress.data.result
                }else{
                    console.log('暂无数据');
                }
                console.log(goodsLists);
                this.setData({
                  goodsLists
                })
              })
        }else if(e.currentTarget.dataset.index==2){
            goodsList({nameLike: e.detail.value,orderBy:'ordersUp'}).then(ress => {
                console.log('123', ress);
                if(ress.data){
                    goodsLists=ress.data.result
                }else{
                    console.log('暂无数据');
                }
                console.log(goodsLists);
                this.setData({
                  goodsLists
                })
              })
        }else if(e.currentTarget.dataset.index==3){
            goodsList({nameLike: e.detail.value,orderBy:'priceUp'}).then(ress => {
                console.log('123', ress);
                if(ress.data){
                    goodsLists=ress.data.result
                }else{
                    console.log('暂无数据');
                }
                console.log(goodsLists);
                this.setData({
                  goodsLists
                })
              })
        }
    },
    getinputvalue(e){
        let {goodsLists,history}=this.data
        console.log(e.detail.value);
        goodsList({nameLike: e.detail.value}).then(ress => {
            console.log('123', ress);
            if(ress.data){
                goodsLists=ress.data.result
            }else{
                goodsLists=[]
                console.log('暂无数据');
            }
            console.log(goodsLists);
            this.setData({
              goodsLists
            })
          })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})